﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code.DAL;
using Manager.App_Code.IDAL;
using Manager.App_Code.DTO;
using Manager.FormAdd_Edit;
namespace Manager.FormMain
{
    public partial class Frm_BarButton_TienNghi : DevExpress.XtraEditors.XtraForm
    {
        public Frm_BarButton_TienNghi()
        {
            InitializeComponent();
        }

        private void Frm_BarButton_TienNghi_Load(object sender, EventArgs e)
        {
            ITienNghi iTienNghi = new TienNghiDAL();
            gridControl1.DataSource = iTienNghi.GetListTienNghi();
        }

        private void butThemMoi_Click(object sender, EventArgs e)
        {
            frm_TienNghiPhong tiennghi = new frm_TienNghiPhong();
            tiennghi.ShowDialog();
            Frm_BarButton_TienNghi_Load(sender, e);
        }

        private void butXoa_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                ITienNghi itiennghi = new TienNghiDAL();
                int index = gridView1.FocusedRowHandle;
                TienNghiDTO tiennghidto = itiennghi.GetTienNghiByID(gridView1.GetRowCellValue(index, MaTienNghi).ToString());

                if (itiennghi.DeleteTienNghi(tiennghidto))
                {
                    MessageBox.Show("Xóa dữ liệu thành công!");
                    this.Frm_BarButton_TienNghi_Load(sender, e);
                }
                else
                    MessageBox.Show("Xóa dữ liệu thất bại!");

            }
        }

        private void butHieuChinh_Click(object sender, EventArgs e)
        {
            ITienNghi iTienNghi = new TienNghiDAL();
            int index = gridView1.FocusedRowHandle;

            TienNghiDTO tiennghidto = iTienNghi.GetTienNghiByID(gridView1.GetRowCellValue(index, MaTienNghi).ToString());
            frm_TienNghiPhong tiennghi = new frm_TienNghiPhong(tiennghidto);
            tiennghi.ShowDialog();
            Frm_BarButton_TienNghi_Load(sender, e);
        }
    }
}